﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace PizzaWic.customer
{
    public partial class DisplayProduct : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            SqlAccess sql = new SqlAccess();
            DataSet data = sql.getAllProducts();

            for (int table = 0; table < data.Tables.Count; table++)
            {
                DataTable dataTable = data.Tables[table];
                for (int row = 0; row < dataTable.Rows.Count; row++)
                {
                    string[] dataString = new string[dataTable.Columns.Count + 2];

                    for (int column = 0; column < dataTable.Columns.Count; column++)
                    {
                        dataString[column] = dataTable.Rows[row][column].ToString();
                    }

                    Object[] param = new Object[1];
                    param[0] = int.Parse(dataString[0]);
                    DataSet data2 = sql.getRawMaterialByProduct(param);
                    string ingredient = "";
                    Boolean disponibilite=true;

                    for (int table2 = 0; table2 < data2.Tables.Count; table2++)
                    {
                        DataTable dataTable2 = data2.Tables[table];

                        for (int row2 = 0; row2 < dataTable2.Rows.Count; row2++)
                        {
                            if(int.Parse(dataTable2.Rows[row2][2].ToString())<int.Parse(dataTable2.Rows[row2][3].ToString())){
                                disponibilite=false;
                            }
                            ingredient += dataTable2.Rows[row2][1].ToString();
                            if (row2 != dataTable2.Rows.Count - 1)
                            {
                                ingredient += ", ";
                            }
                        }
                    }

                    dataString[dataString.Length - 2] = ingredient;
                    dataString[dataString.Length - 1] = disponibilite.ToString();
                    productItem item = (productItem)LoadControl("~/customer/productItem.ascx");

                    if (dataString[2] == "Pizza")
                        pizza.Controls.Add(item);

                    else if (dataString[2] == "Boisson")
                        drink.Controls.Add(item);

                    else if (dataString[2] == "Dessert")
                        dessert.Controls.Add(item);

                    item.setData(dataString);

                }
            }

        }
    }
}